package com.sdhs.framework.web.service;

import com.sdhs.common.core.domain.model.FinanceBody;
import com.sdhs.common.core.domain.model.HrLeaveBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * 公共数据接口
 */
@Component
public class SysPublicService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 保存财务数据
     * @param finance
     */
    public void addFinance(FinanceBody finance){
        String sql =" INSERT INTO fee_inform " +
                " (claimant,amount,reimburse_date,fee_type,bill_title,bill_creator_phone)" +
                " values" +
                " (?,?,?,?,?,?)";
        this.jdbcTemplate.update(sql,new Object[]{finance.getBillCreatorName(),finance.getBillAmount().replaceAll(",",""),finance.getBillDate(),
        finance.getBillType(),finance.getBillTitle(),finance.getBillCreatorPhone()});
    }


    /**
     * 保存请假数据
     * @param hrLeave
     */
    public void addHrLeave(HrLeaveBody hrLeave){
        String sql = " INSERT INTO hr_leave" +
                "(approve_type,approve_long,start_time,end_time,approve_end_time,post_name,username,post_dept,post_company,delete_flag,create_date)" +
                "values" +
                "('0',?,?,?,?,?,?,?,?,'0',now())";
        this.jdbcTemplate.update(sql,new Object[]{hrLeave.getApproveLong(),hrLeave.getStartTime(),
                hrLeave.getEndTime(),hrLeave.getApproveEndTime(),
                hrLeave.getPostName(), hrLeave.getUsername(),
                hrLeave.getPostDept(),hrLeave.getPostCompany()});
    }
}
